#include "LeFrntTrunLampView.h"
#include "F3LampInterfaces.h"

static void leturnCanSignalFeedback()
{
    Set_CANSIG_LeFrntTurnLampOnSt(LocalQuery_LeFrntTurnLampOnSt());
}

float calculateLeturnDerateCoefficient()
{
    float coefficient = LocalQuery_LobeamBrightness_Temperature();    
    float coefficient_v = LocalQuery_LobeamBrightness_Voltage();
    coefficient = coefficient < coefficient_v ? coefficient : coefficient_v;

    return coefficient;
}

void execute_LeFrntTrunLampView(LeFrntTrunLampView* this_)
{
    uint32_t mask = this_->model_->mask ^ this_->lastModel_.mask;
    leturnCanSignalFeedback();

    if(mask)
    {
        float coefficient = calculateLeturnDerateCoefficient();
        if(coefficient > 0.0)   
        {
            Set_LampCtrl_TurnLampsStatus(mask, this_->model_->mask, this_->model_->pwm_ * coefficient / 100.0f);
        }
        else
        {
            Set_LampCtrl_TurnLampsStatus(mask, 0, 0.0);
        }
    }
}

